<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>魔术索引</title>
</head>
<body>
  <script>
    function fn(nums) {
      let i = 0;
      if (!nums.length) {
        return -1;
      } else {
        while (i <= nums.length && i !== nums[i]) {
          i++;
        }
        let min = i > nums.length ? -1 : i;
        return min;
      }
    }
    console.log(fn([0, 2, 3, 4, 5]))
  </script>
</body>
</html>